package com.ylbh.modules.finance.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.finance.dto.FinanceDTO;
import com.ylbh.common.pojo.finance.dto.FinanceDetailsDTO;
import com.ylbh.common.pojo.finance.dto.FinanceListDTO;
import com.ylbh.common.pojo.finance.vo.FinanceDetailsVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.business.service.ShoppingUserService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * 财务 ->运营打款
 * @author czx
 * @date 2019-04-29 14:46:58
 */
@RestController
@RequestMapping("user/finance")
public class FinanceController {

    @Autowired
    private ShoppingUserService shoppingUserService;

    @ApiOperation("运营打款列表")
    @RequestMapping("queryFinanceList")
    @RequiresPermissions("user:finance:queryFinanceList")
    public CommonResult<PageUtils> queryFinanceList(FinanceListDTO financeListDTO) {
        PageUtils list = shoppingUserService.queryFinanceList(financeListDTO);
        return Ref.ok(list);
    }

    @ApiOperation("商家详情")
    @RequestMapping("getFinanceById/{id}")
//    @RequiresPermissions("user:finance:getFinanceById")
    public CommonResult<FinanceDetailsVO> getFinanceById(@PathVariable(value = "id")Long id) {
        FinanceDetailsVO vo = shoppingUserService.getFinanceById(id);
        return Ref.ok(vo);
    }

    @SysLog("商家详情修改")
    @ApiOperation("商家详情修改")
    @RequestMapping("modifyFinanceById")
    @RequiresPermissions("user:finance:modifyFinanceById")
    public CommonResult<Void> modifyFinanceById(@RequestBody FinanceDetailsDTO financeDetailsDTO) {
        shoppingUserService.modifyFinanceById(financeDetailsDTO);
        return Ref.ok();
    }

    @SysLog("打款提交")
    @ApiOperation("打款提交")
    @RequestMapping("modifyMoneyById")
    @RequiresPermissions("user:finance:modifyMoneyById")
    public CommonResult<String> modifyMoneyById(@RequestBody FinanceDTO financeDTO) {
        String msg = shoppingUserService.modifyMoneyById(financeDTO);
        if ("打款成功".equals(msg))
            return Ref.ok(msg);
        else
            return Ref.error(msg);
    }

}
